<html>
<head>
<link rel="shortcut icon" href="./favicon.ico">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="canonical" href="./Hamming_Distance.html">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Returns the number of bits which are different between two words.  Returns a WORD_WIDTH integer, which will get optimized down to using only the floor(log<sub>2</sub>(N))+1 least-significant bits.">
<title>Hamming Distance</title>
</head>
<body>

<p class="inline bordered"><b><a href="./Hamming_Distance.v">Source</a></b></p>
<p class="inline bordered"><b><a href="./legal.html">License</a></b></p>
<p class="inline bordered"><b><a href="./index.html">Index</a></b></p>

<h1>Hamming Distance</h1>
<p>Returns the number of bits which are different between two words.  Returns
 a WORD_WIDTH integer, which will get optimized down to using only the
 floor(log<sub>2</sub>(N))+1 least-significant bits.</p>

<pre>
`default_nettype none

module <a href="./Hamming_Distance.html">Hamming_Distance</a>
#(
    parameter WORD_WIDTH    = 0
)
(
    input   wire    [WORD_WIDTH-1:0]    word_A,
    input   wire    [WORD_WIDTH-1:0]    word_B,
    output  wire    [WORD_WIDTH-1:0]    distance
);

    wire [WORD_WIDTH-1:0] different_bits;

    <a href="./Word_Reducer.html">Word_Reducer</a>
    #(
        .OPERATION  ("XOR"),
        .WORD_WIDTH (WORD_WIDTH),
        .WORD_COUNT (2)
    )
    compare_bits
    (
        .words_in   ({word_A, word_B}),
        .word_out   (different_bits)
    );

    <a href="./Population_Count.html">Population_Count</a>
    #(
        .WORD_WIDTH (WORD_WIDTH)
    )
    calc_hamming_dist
    (
        .word_in    (different_bits),
        .count_out  (distance)
    );

endmodule
</pre>

<hr>
<p><a href="./index.html">Back to FPGA Design Elements</a>
<center><a href="https://fpgacpu.ca/">fpgacpu.ca</a></center>
</body>
</html>

